(function (vc, vm) {

    vc.extends({
        data: {
            auditAffiliateWithdrawalInfo: {
                awId: '',
                amount: '',
                fee: '',
                state: '',
                realAmount: '',
                auditRemark: '',
                remark:'',
            }
        },
        _initMethod: function () {

        },
        _initEvent: function () {
            vc.on('auditAffiliateWithdrawal', 'openAuditAffiliateWithdrawalModal', function (_params) {
                vc.component.refreshAuditAffiliateWithdrawalInfo();
                $('#auditAffiliateWithdrawalModel').modal('show');
                vc.copyObject(_params, vc.component.auditAffiliateWithdrawalInfo);
                vc.component.auditAffiliateWithdrawalInfo.communityId = vc.getCurrentCommunity().communityId;
            });
        },
        methods: {
            auditAffiliateWithdrawalValidate: function () {
                return vc.validate.validate({
                    auditAffiliateWithdrawalInfo: vc.component.auditAffiliateWithdrawalInfo
                }, {
                    'auditAffiliateWithdrawalInfo.amount': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "提现金额不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "30",
                            errInfo: "提现金额不能超过30"
                        },
                    ],
                    'auditAffiliateWithdrawalInfo.fee': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "手续费不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "200",
                            errInfo: "手续费不能为空"
                        },
                    ],
                    'auditAffiliateWithdrawalInfo.state': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "状态不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "10",
                            errInfo: "状态不能为空"
                        },
                    ],
                    'auditAffiliateWithdrawalInfo.realAmount': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "实际到账金额不能为空"
                        },
                    ],
                    'auditAffiliateWithdrawalInfo.auditRemark': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "原因不能为空"
                        },
                    ],
                    'auditAffiliateWithdrawalInfo.awId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "提现ID不能为空"
                        }]

                });
            },
            auditAffiliateWithdrawal: function () {
                if (!vc.component.auditAffiliateWithdrawalValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }

                vc.http.apiPost(
                    'affiliateWithdrawal.auditAffiliateWithdrawal',
                    JSON.stringify(vc.component.auditAffiliateWithdrawalInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#auditAffiliateWithdrawalModel').modal('hide');
                            vc.emit('affiliateWithdrawalManage', 'listAffiliateWithdrawal', {});
                            return;
                        }
                        vc.message(_json.msg);
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');

                        vc.message(errInfo);
                    });
            },
            refreshAuditAffiliateWithdrawalInfo: function () {
                vc.component.auditAffiliateWithdrawalInfo = {
                    awId: '',
                    amount: '',
                    fee: '',
                    realAmount:'',
                    auditRemark: '',
                    state: '',
                    accountType:'',
                    userName: '',
                    totalCommission: '',
                    withdrawnCommission: '',
                    availableCommission: '',
                    remark:'',

                }
            },
            _state: function (_state) {
                if(_state == "0"){
                    return "申请中"
                }
                if(_state == "1"){
                    return "处理中"
                }
                if(_state == "2"){
                    return "已完成"
                }
                if(_state == "3"){
                    return "已拒绝"
                }
            },
            _account_type: function (__account_type){
                if(__account_type == "1"){
                    return "支付宝"
                }
                if(__account_type == "2"){
                    return "微信"
                }
                if(__account_type == "3"){
                    return "银行卡"
                }
            }
        }
    });

})(window.vc, window.vc.component);
